/*
 * cprogmodel.c - Guess C programming model
 * Reference: http://www.unix.org/whitepapers/64bit.html
 * Copyright (c) 2011 Rudá Moura <ruda.moura@gmail.com> 
 */

#include <stdio.h>

char *
cprogmodel(void)
{
	if (sizeof(int) == 2 && sizeof(long) == 4 && sizeof(void*) == 4)
		return "LP32";
	if (sizeof(int) == 4 && sizeof(long) == 4 && sizeof(void*) == 4)
		return "ILP32";
	if (sizeof(int) == 4 && sizeof(long) == 8 && sizeof(void*) == 8)
		return "LP64";
	if (sizeof(int) == 8 && sizeof(long) == 8 && sizeof(void*) == 8)
		return "ILP64";
	if (sizeof(long) == 4 && sizeof(long long) == 8 && sizeof(void*) == 8)
		return "LLP64";
	/* Can't detect model */
	return NULL;
}

int
main()
{
	char *model = cprogmodel();
	if (model == NULL)
		return 1;
	puts(model);
	return 0;
}
